﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UI_Trigger : MonoBehaviour {

    public Transform[] Poss;

    public Slider BGMSlider;

    public Slider SESlider;

    enum TriggerType
    {
        BGM,
        SE,
        OUT
    }

    private TriggerType nowType = TriggerType.BGM;

    private TriggerType NowType
    {
        set
        {
            transform.position = Poss[(int)value].position;
            nowType = value;
        }
        get
        {
            return nowType;
        }
    }

    public void Up()
    {
        if(NowType == TriggerType.BGM)
        {
            return;
        }
        GetComponent<AudioPro>().Play();
        NowType--;
    }

    public void Down()
    {
        if (NowType == TriggerType.OUT)
        {
            return;
        }
        GetComponent<AudioPro>().Play();
        NowType++;
    }

    public void Left()
    {
        switch (NowType)
        {
            case TriggerType.BGM:
                {
                    BGMSlider.value--;
                    break;
                }
            case TriggerType.SE:
                {
                    SESlider.value--;
                    break;
                }
        }
    }

    public void Right()
    {
        switch (NowType)
        {
            case TriggerType.BGM:
                {
                    BGMSlider.value++;
                    break;
                }
            case TriggerType.SE:
                {
                    SESlider.value++;
                    break;
                }
        }
    }

    private void Update()
    {
        if (InputManager.Instance.GetTheKeyDown(DefineInputKeyMeans.UP))
        {
            Up();
            return;
        }
        if (InputManager.Instance.GetTheKeyDown(DefineInputKeyMeans.RIGHT))
        {
            Right();
        }
        if (InputManager.Instance.GetTheKeyDown(DefineInputKeyMeans.LEFT))
        {
            Left();
        }
        if (InputManager.Instance.GetTheKeyDown(DefineInputKeyMeans.DOWN))
        {
            Down();
        }
        if(InputManager.Instance.GetTheKeyDown(DefineInputKeyMeans.ESC) 
            || ((InputManager.Instance.GetTheKeyDown(DefineInputKeyMeans.ENTER))
            &&nowType==TriggerType.OUT))
        {
            GameObject.FindGameObjectWithTag(Tag.setting).
                GetComponent<SettingPanel>().Back();
        }
    }

}
